<!-- <!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>vue中v-if的常见使用</title>
    <script src="vue.js"></script>
    <script>
        window.onload = function() {
            //创建vue实例
            var vm = new Vue({
                el: '#app',
                data: {
                    type: 'c',
                    logintype: 'username'
                },
                methods: {
                    changeloginType() {
                        let self = this;
                        if (self.logintype == 'username') {
                            self.logintype = '';
                        } else {
                            self.logintype = 'username';
                        }
                    }
                }
            })
        }
    </script>
</head>

<body>
    <div id="app">
        <div style="color: antiquewhite;">v-if的简单使用</div>
        <template>
            <div v-if="type=='a'">a</div>
            <div v-else-if="type='b'">b</div>
            <div v-else >c</div>
        </template>
        <div>v-if弹窗切换</div>
        <template v-if="logintype==='username'">
            <label for="username">用户名：</label>
            <input type="text" name="" id="" placeholder="enter username" key="username-input">
        </template>
        <template v-else>
            <label for="password">密码：</label>
            <input type="text" placeholder="enter password" key="username-password">
            <button @click="changeloginType">状态切换</button>
        </template>
    </div>
</body>

</html> -->


<!-- csdn-code -->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Vue中v-if的常见使用</title>
    <script src="https://cdn.bootcss.com/vue/2.5.17-beta.0/vue.js"></script>
</head>
<script>
    window.onload = function() {

        //创建一个vue实例
        var app = new Vue({
            el: '#app',
            data: {
                type: 'C',
                loginType: 'username'
            },
            methods: {
                changeloginType() {
                    let self = this;
                    if (self.loginType == 'username') {
                        self.loginType = ''
                    } else {
                        self.loginType = 'username'
                    }
                }
            }
        })
    }
</script>

<body>
    <div id="app">
        <div style="color:red">v-if的简单实用</div>
        <template>
            <div v-if="type == 'A'">
                A
            </div>
            <div v-else-if="type=='B'">
                B
            </div>
            <div v-else>
                C
            </div>
        </template>
        <div style="color:green">v-if的弹框切换</div>
        <template v-if="loginType === 'username'">
            <label>用户名：</label>
            <input placeholder="Enter your username" key="username-input">
        </template>
        <template v-else>
            <label>密码：</label>
            <input placeholder="Enter your email address" key="email-input">
        </template>
        <button @click="changeloginType">切换状态</button>
    </div>
</body>

</html>